
package com.probiz.estoresa.customer.web.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.apache.commons.lang.StringUtils;
import org.springframework.validation.BindException;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.servlet.ModelAndView;

import com.probiz.estore.Constants;
import com.probiz.estore.common.helper.AttributeUtil;
import com.probiz.estore.common.model.attribute.AttributeValue;
import com.probiz.estore.common.model.customer.Address;
import com.probiz.estore.common.model.customer.Consult;
import com.probiz.estore.common.model.customer.Customer;
import com.probiz.estore.common.model.customer.Feedback;
import com.probiz.estore.common.model.customer.Membership;
import com.probiz.estore.common.model.customer.ShopPoint;
import com.probiz.estore.common.model.customer.ShopPointHistory;
import com.probiz.estore.common.model.order.SalesOrder;
import com.probiz.estore.common.model.other.Tag;
import com.probiz.estore.common.model.product.ProductReview;
import com.probiz.estore.common.model.system.AppUser;
import com.probiz.estore.core.controller.GenericStoreAdminController;
import com.probiz.estore.core.exception.ApplicationException;
import com.probiz.estore.core.model.BaseObject;
import com.probiz.estore.core.search.SearchCriteria;
import com.probiz.estore.core.util.I18nUtil;
import com.probiz.estore.customer.model.CustomerFullyModel;
import com.probiz.estore.customer.model.CustomerSearchCriteria;
import com.probiz.estore.customer.service.AddressManager;
import com.probiz.estore.customer.service.ConsultManager;
import com.probiz.estore.customer.service.CustomerManager;
import com.probiz.estore.customer.service.FeedbackManager;
import com.probiz.estore.customer.service.MembershipManager;
import com.probiz.estore.customer.service.ShopPointHistoryManager;
import com.probiz.estore.customer.service.ShopPointManager;
import com.probiz.estore.order.model.OrderSearchCriteria;
import com.probiz.estore.order.service.SalesOrderManager;
import com.probiz.estore.other.service.TagManager;
import com.probiz.estore.product.service.ProductReviewManager;
import com.probiz.estore.system.service.MsgSendManager;
import com.probiz.estore.system.util.MsgTemplateConstants;
import com.probiz.estore.webapp.util.RequestUtil;

public class CustomerController extends GenericStoreAdminController<Customer> {
	private CustomerManager		customerManager		= null;
	private MembershipManager 	membershipManager  	= null;
	private TagManager tagManager = null;
	private ProductReviewManager productReviewManager =null;
	private ConsultManager  consultManager = null;
	private FeedbackManager  feedbackManager = null;
	private SalesOrderManager salesOrderManager = null;
	private ShopPointHistoryManager shopPointHistoryManager = null;
	private ShopPointManager shopPointManager = null; 
	private AddressManager addressManager = null;
	private MsgSendManager msgSendManager = null;

	public MsgSendManager getMsgSendManager() {
		return msgSendManager;
	}


	public void setMembershipManager(MembershipManager membershipManager) {
		this.membershipManager = membershipManager;
	}

	public void setCustomerManager(CustomerManager manager) {
		this.customerManager = manager;
	}
	

	public void setTagManager(TagManager tagManager) {
		this.tagManager = tagManager;
	}
	

	public void setProductReviewManager(ProductReviewManager productReviewManager) {
		this.productReviewManager = productReviewManager;
	}
	

	public void setConsultManager(ConsultManager consultManager) {
		this.consultManager = consultManager;
	}

	public void setFeedbackManager(FeedbackManager feedbackManager) {
		this.feedbackManager = feedbackManager;
	}

	public void setSalesOrderManager(SalesOrderManager salesOrderManager) {
		this.salesOrderManager = salesOrderManager;
	}
	

	public void setShopPointHistoryManager(ShopPointHistoryManager shopPointHistoryManager) {
		this.shopPointHistoryManager = shopPointHistoryManager;
	}
	
	

	public void setShopPointManager(ShopPointManager shopPointManager) {
		this.shopPointManager = shopPointManager;
	}
	

	public void setAddressManager(AddressManager addressManager) {
		this.addressManager = addressManager;
	}
	

	public void setMsgSendManager(MsgSendManager msgSendManager) {
		this.msgSendManager = msgSendManager;
	}

	@Override
	protected String getEntityName(Customer entity) {
		return entity.getUsername();
	}

	

	@Override
	protected void initController() throws Exception {
		mgr = customerManager;
	}
	
	
	@Override
	protected void onShowForm(HttpServletRequest request, ModelAndView mv){
		mv.addObject("membershipList", membershipManager.getAllMembershipsOrderByLevel(true));
		
		Customer customer = formBackingObject(request);
		if(customer.getAppuserId()!=null){
			mv.addObject("reviewCount",productReviewManager.getCountsOfCustomer(customer.getAppuserId())[1]);
			mv.addObject("consultCount",consultManager.getCountsOfCustomer(customer.getAppuserId())[0]);
			mv.addObject("feedbackCount",feedbackManager.getCountsOfCustomer(customer.getAppuserId())[0]);
			mv.addObject("salesOrderCount",salesOrderManager.countCustomerOrder(customer.getAppuserId()));
			mv.addObject("addressCount",addressManager.countAddressOfCustomer(customer.getAppuserId()));
		}
		
	}
	@Override
	public ModelAndView defaultAction(HttpServletRequest request,
			HttpServletResponse response) {
		ModelAndView mv = new ModelAndView("customer/customerList");
		List<Membership> membershipList = membershipManager.getAllMembershipsOrderByLevel(true);
		mv.addObject("membershipList", membershipList);
		return mv;
	}
	@Override
	public ModelAndView search(HttpServletRequest request,HttpServletResponse response) {
		ModelAndView mv = new ModelAndView("customer/include/customerListBody");
		SearchCriteria searchCriteria = createSearchCriteria(request);
		CustomerSearchCriteria customerSearchCriteria = new CustomerSearchCriteria();
		try {
			// 绑定参数
			bind(request, customerSearchCriteria);
			List<Customer> customerList = customerManager.searchByCriteriaForController(customerSearchCriteria,	searchCriteria);
			mv.addObject("customerList", customerList);
			mv.addObject("customerSearchCriteria", customerSearchCriteria);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return mv;
	}
	
	/**
	 * 获得订单列表
	 * @param request
	 * @param response
	 * @return
	 */
	public ModelAndView getSalesOrderList(HttpServletRequest request,HttpServletResponse response) {
		
		ModelAndView mv = new ModelAndView("customer/include/customerFormSalesOrder");
		Customer customer = this.formBackingObject(request);
		try {
			OrderSearchCriteria orderSearchCriteria = new OrderSearchCriteria();
			orderSearchCriteria.setCustomerId(customer.getAppuserId());
			SearchCriteria searchCriteria = salesOrderManager.getSearchCriteriaBuilder(BaseObject.FilterHqlName.DEFAULT).buildSearchCriteria(request, defaultPageSize);
			List<SalesOrder> salesOrderList = salesOrderManager.searchByCriteriaForController(orderSearchCriteria, searchCriteria);
			mv.addObject("salesOrderList", salesOrderList);
			mv.addObject("sc", searchCriteria); //必须重新把sc放到页面中。
			mv.addObject("customer", customer);
			mv.addObject("pagingId", request.getParameter("pagingId"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return mv;
	}
	/**
	 * 获得地址列表
	 * @param request
	 * @param response
	 * @return
	 */
	public ModelAndView getAddressList(HttpServletRequest request,HttpServletResponse response) {
		
		ModelAndView mv = new ModelAndView("customer/include/customerFormAddress");
		Customer customer = this.formBackingObject(request);
		try {
			SearchCriteria sc = addressManager.getSearchCriteriaBuilder(Address.FilterHqlName.MY_ADDRESS_LIST).buildSearchCriteria(request, defaultPageSize);
			sc.addParamValue(customer.getAppuserId());
			List<Address> addressList = this.searchByCriteria(sc);
			
			mv.addObject("addressList", addressList);
			mv.addObject("sc", sc); //必须把sc设置到request中
			mv.addObject("customer", customer);
			mv.addObject("pagingId", request.getParameter("pagingId"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return mv;
	}
	 
	
	/**
	 * 获得积分历史列表
	 * @param request
	 * @param response
	 * @return
	 */
	public ModelAndView getShopPointHistoryList(HttpServletRequest request,HttpServletResponse response) {
		ModelAndView mv = new ModelAndView("customer/include/customerFormShopPointHistory");
		Customer customer = this.formBackingObject(request);
		try {
			SearchCriteria sc = shopPointHistoryManager.getSearchCriteriaBuilder(ShopPointHistory.FilterHqlName.MY_HISTORY_LIST).buildSearchCriteria(request, defaultPageSize);
			sc.addParamValue(customer.getAppuserId());
			List<ShopPointHistory> shopPointHistoryList = this.searchByCriteria(sc);
			
			mv.addObject("shopPointHistoryList", shopPointHistoryList);
			mv.addObject("sc", sc); //必须把sc设置到request中
			mv.addObject("customer", customer);
			mv.addObject("pagingId", request.getParameter("pagingId"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return mv;
	}
	/**
	 * 积分列表重新加载
	 * @param request
	 * @param response
	 * @return
	 */
	public ModelAndView loadShopPointTab(HttpServletRequest request,HttpServletResponse response) {
		ModelAndView mv = new ModelAndView("customer/include/customerFormShopPoint");
		Customer customer = this.formBackingObject(request);
		try {
			SearchCriteria sc = shopPointHistoryManager.getSearchCriteriaBuilder(ShopPointHistory.FilterHqlName.MY_HISTORY_LIST).buildSearchCriteria(request, defaultPageSize);
			sc.addParamValue(customer.getAppuserId());
			List<ShopPointHistory> shopPointHistoryList = this.searchByCriteria(sc);
			
			mv.addObject("shopPointHistoryList", shopPointHistoryList);
			mv.addObject("sc", sc); //必须把sc设置到request中
			mv.addObject("customer", customer);
			mv.addObject("pagingId", "ShopPointHistory");
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return mv;
	}
	/**
	 * 调整积分
	 * @param request
	 * @param response
	 * @return
	 */
	public ModelAndView adjustShopPoint(HttpServletRequest request,HttpServletResponse response) {
		Map<String,Object> map = new HashMap<String,Object>();
		Customer customer = this.formBackingObject(request);
		Integer amount = RequestUtil.getInteger(request, "amount");
		Integer direction = RequestUtil.getInteger(request, "direction");
		if(direction < 0){
			amount = -amount;
		}
		String description = RequestUtil.getParameterNullSafe(request, "description");
		boolean result = shopPointManager.updateShopPoint(customer, amount, ShopPoint.TYPE_MANUAL, null, description);
		map.put("customerId", customer.getAppuserId());
		map.put("result", result);
		return this.getModelAndAjaxJsonView(map);
	}
	/**
	 * 获得评论列表
	 * @param request
	 * @param response
	 * @return
	 */
	public ModelAndView getReviewList(HttpServletRequest request,HttpServletResponse response) {
		
		ModelAndView mv = new ModelAndView("customer/include/customerFormReview");
		Customer customer = this.formBackingObject(request);
		try {
			SearchCriteria sc = productReviewManager.getSearchCriteriaBuilder(ProductReview.FilterHqlName.MY_REVIEW_LIST).buildSearchCriteria(request, defaultPageSize);
			sc.addParamValue(customer.getAppuserId());
			List<ProductReview> productReviewList = this.searchByCriteria(sc);
			
			mv.addObject("productReviewList", productReviewList);
			mv.addObject("sc", sc); //必须把sc设置到request中
			mv.addObject("customer", customer);
			mv.addObject("pagingId", request.getParameter("pagingId"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return mv;
	}
	
	/**
	 * 获得咨询列表
	 * @param request
	 * @param response
	 * @return
	 */
	public ModelAndView getConsultList(HttpServletRequest request,HttpServletResponse response) {
		
		ModelAndView mv = new ModelAndView("customer/include/customerFormConsult");
		Customer customer = this.formBackingObject(request);
		try {
			SearchCriteria sc = consultManager.getSearchCriteriaBuilder(Consult.FilterHqlName.MY_CONSULT_LIST).buildSearchCriteria(request, defaultPageSize);
			sc.addParamValue(customer.getAppuserId());
			List<Consult> consultList = this.searchByCriteria(sc);
			
			mv.addObject("consultList", consultList);
			mv.addObject("sc", sc); //必须把sc设置到request中
			mv.addObject("customer", customer);
			mv.addObject("pagingId", request.getParameter("pagingId"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return mv;
	}
	
	/**
	 * 获得反馈列表
	 * @param request
	 * @param response
	 * @return
	 */
	public ModelAndView getFeedbackList(HttpServletRequest request,HttpServletResponse response) {
		
		ModelAndView mv = new ModelAndView("customer/include/customerFormFeedback");
		Customer customer = this.formBackingObject(request);
		try {
			SearchCriteria sc = feedbackManager.getSearchCriteriaBuilder(Feedback.FilterHqlName.MY_FEEDBACK_LIST).buildSearchCriteria(request, defaultPageSize);
			sc.addParamValue(customer.getAppuserId());
			List<Feedback> feedbackList = this.searchByCriteria(sc);
			
			mv.addObject("feedbackList", feedbackList);
			mv.addObject("sc", sc); //必须把sc设置到request中
			mv.addObject("customer", customer);
			mv.addObject("pagingId", request.getParameter("pagingId"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return mv;
	}
	
	@Override
	protected void preSave(HttpServletRequest request, Customer entity,
			BindException errors) {
		
	}
	protected void preSave(HttpServletRequest request, Customer customer, Map<String, Object> data) {
		if (customer.getAppuserId()==null) {
			boolean isDuplicate = customerManager.getIsUserExist(customer.getUsername());
			if (isDuplicate) {
				//检查账户是否重复
				Object[] params = { customer.getUsername() };
				data.put("error", I18nUtil.getInstance().getMessage("appUser.username.isExist", params));
			} else if (customerManager.getIsEmailExist(customer.getEmail())) {
				//检查邮件地址是否已存在
				data.put("error", I18nUtil.getInstance().getMessage("appUser.email.isExist"));
			}
		} else {
			//检查修改后的邮件是否已经存在
			if (customerManager.getIsEmailUseByOthers(customer.getEmail(), customer.getAppuserId())) {
				data.put("error", I18nUtil.getInstance().getMessage("appUser.email.isExist"));
			}
		}
	}
	
	@Override
	public ModelAndView save(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String, Object> data = new HashMap<String, Object>();
		Customer customer = this.formBackingObject(request);
		BindException errors = null;
		try {
			ServletRequestDataBinder binder = bindAndValidate(request, customer);
			errors = new BindException(binder.getBindingResult());
			preSave(request, customer, data);
			if (!data.containsKey("error")) {
				
				CustomerFullyModel model = new CustomerFullyModel();
				model.setCustomer(customer);
				List<AttributeValue> list = AttributeUtil.getInstance().getAttributeFromRequest(request);
				model.setAttributeValues(list);
				if (isEntityNew(request)) {
					customerManager.addCustomer(model, Constants.STATUS_ACTIVE); //后台添加的立即激活
					Map<String, Object> modelMsg = new HashMap<String, Object>();
					modelMsg.put("customer", customer);
					msgSendManager.sendMsg(MsgTemplateConstants.MESSAGE_FRONT_USER_ACTIVATION, modelMsg, 
							null, 
							null != customer.getCustomerId() ? new String[]{customer.getCustomerId().toString()} : null, 
							null != customer.getMobilephone() ? new String[]{customer.getMobilephone()} : null);//激活用户，并发送系统消息
				} else {
					customerManager.saveFully(model);
				}
			}
		} catch (ApplicationException e) {
			handleApplicationException(errors, e);
		}

		return this.getModelAndAjaxJsonView(data);
	}
	
	/*
	 * (non-Javadoc)
	 * @see com.probiz.estore.core.controller.GenericStoreAdminController#delete(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	public ModelAndView delete(HttpServletRequest request,	HttpServletResponse response) throws Exception {
		Map<String, Object> data = new HashMap<String, Object>();
		Customer customer = this.formBackingObject(request);
		String msg = getMessage("common.deleted", new Object[] {
				getEntityTypeMessage(), customer.getUsername() });
		customerManager.deleteFully(customer);
		data.put("msg",msg);
		return getModelAndAjaxJsonView(data);
	}
	@Override
	public ModelAndView multiDelete(HttpServletRequest request,	HttpServletResponse response) {
		Map<String, Object> data = new HashMap<String, Object>();
		String[] pkeys = request.getParameterValues("multiIds");
		if (pkeys != null) {
			StringBuffer names = new StringBuffer();
			for (int i = 0; i < pkeys.length; i++) {
				if (pkeys[i] != null && !pkeys[i].equals("")) {
					Customer customer = customerManager.getByAppUserId(new Integer(pkeys[i]));
					names.append(customer.getUsername() + ","); //必须在deleteFully前，因为删除后username已更改
					customerManager.deleteFully(customer);
				}
			}
			String msg = getMessage("customer.deleted",	new Object[] { names.toString().substring(0, names.length() - 1) });
			msg = msg.replace("：", ":");
			msg = (msg.split(":"))[0];
			data.put("msg",msg);
		}

		return getModelAndAjaxJsonView(data);
	}
	
	public ModelAndView multiActive(HttpServletRequest request,	HttpServletResponse response) {
		Map<String, Object> data = new HashMap<String, Object>();
		String[] pkeys = request.getParameterValues("multiIds");
		if (pkeys != null) {
			StringBuffer names = new StringBuffer();
			for (int i = 0; i < pkeys.length; i++) {
				if (pkeys[i] != null && !pkeys[i].equals("")) {
					Customer customer = customerManager.getByAppUserId(new Integer(pkeys[i]));
					customerManager.doActiveCustomer(customer);
					names.append(customer.getUsername() + ",");
				}
			}
			String msg = getMessage("customer.active",	new Object[] { names.toString().substring(0, names.length() - 1) });
			data.put("msg",msg);
		}

		return getModelAndAjaxJsonView(data);
	}
	
	public ModelAndView multiForbid(HttpServletRequest request,	HttpServletResponse response) {
		Map<String, Object> data = new HashMap<String, Object>();
		String[] pkeys = request.getParameterValues("multiIds");
		if (pkeys != null) {
			StringBuffer names = new StringBuffer();
			for (int i = 0; i < pkeys.length; i++) {
				if (pkeys[i] != null && !pkeys[i].equals("")) {
					Customer customer = customerManager.getByAppUserId(new Integer(pkeys[i]));
					customerManager.doForbidCustomer(customer);
					names.append(customer.getUsername() + ",");
				}
			}
			String msg = getMessage("customer.forbid",	new Object[] { names.toString().substring(0, names.length() - 1) });
			data.put("msg",msg);
		}

		return getModelAndAjaxJsonView(data);
	}
	/**
	 * 群发邮件
	 * @param request
	 * @param response
	 * @return
	 */
	public ModelAndView sendMail(HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> data = new HashMap<String, Object>();
		Map map = new HashMap();
		map.put("title", request.getParameter("mailTitle"));
		map.put("content", request.getParameter("content"));
		String[] receivers = RequestUtil.getParameterNullSafe(request, "receivers").split(";");
		try{
			//mailEngine.sendSimpleTemplateMail("customer/customerEmail.vm", map,null,null,receivers);
			msgSendManager.sendMsg(MsgTemplateConstants.MESSAGE_EMAIL_TO_CUSTOMERS, map, receivers, null, null);
		}catch(Exception e){
			e.printStackTrace();
			data.put("error", getMessage("customer.mail.fail"));
		}
		data.put("msg", getMessage("customer.mail.success"));
		return getModelAndAjaxJsonView(data);
	}
	
	/**
	 * 打开重设密码页面
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */ 
    public ModelAndView resetPassword(HttpServletRequest request,HttpServletResponse response) throws Exception {
      ModelAndView mv = new ModelAndView("system/userPasswordForm");
      Customer appuser = customerManager.getById(RequestUtil.getInteger(request,"appuserId"));
      mv.addObject("appuser", appuser);
      return mv;
    }
    /**
     * 保存密码
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ModelAndView saveResetPassword(HttpServletRequest request,
			HttpServletResponse response) throws Exception{
    	Map<String, Object> data = new HashMap<String, Object>();
    	try {
			Integer appuserId = RequestUtil.getInteger(request, "appuserId");
			String password = RequestUtil.getParameterNullSafe(request, "password");
			customerManager.saveModifyPassword(appuserId,password);
			Map msgVariables = new HashMap();
			AppUser appUser = customerManager.getById(appuserId);
			msgVariables.put("userName", appUser.getUsername());
			msgVariables.put("newPassword", password);
			msgSendManager.sendMsg(MsgTemplateConstants.MESSAGE_CHANGE_PASSWORD, msgVariables, new String[]{appUser.getEmail()}, new String[]{ appUser.getAppuserId().toString()}, new String[]{appUser.getMobilephone()});
		} catch (RuntimeException e) {
			data.put("error", e.getMessage());
		}
		return this.getModelAndAjaxJsonView(data);
    }


	
	@Override
	protected Customer formBackingObject(HttpServletRequest request) {
		String entityId = request.getParameter(entityIdName);
		Customer entity = null;

		if (!StringUtils.isEmpty(entityId)) {
			try {
				entity = customerManager.getByAppUserId(new Integer(entityId));
			} catch (Exception ex) {
				logger
						.info(formatMsg(
								"Error retrieving entity [%1 : %2]. So assume it is new.",
								entityClassName, entityId, ex));
				saveMessage(request, getMessage("errors.invalid.edit.id",
						new Object[] { entityId }));
			}
		}
		if (entity == null) {
			try {
				entity = entityClass.newInstance();
			} catch (Throwable e) {
				throw new RuntimeException("Unexpected error!", e);
			}
		}
		request.setAttribute("entityClassName", entityClassName);
		return entity;
	}
	
   
    
    /**
	 * 应用标签
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ModelAndView applyTags(HttpServletRequest request,	HttpServletResponse response) throws Exception {
		Map<String, Object> data = null;
		String tagNames = RequestUtil.getParameterNullSafe(request, "tagNames");
		String[] ids = request.getParameterValues("multiIds");
		if (ids != null && ids.length > 0) {
			for (String entityId : ids) {
				Customer customer = customerManager.getById(Integer.valueOf(entityId));
				data = tagManager.doSetTagField(customer, Tag.MODULE_CUSTOMER, tagNames);
				customerManager.save(customer);
			}
		}
		return getModelAndAjaxJsonView(data);
	}

	/*
	 * 根据客户获取这个客户的信息，缺省地址信息
	 * */
	
	public ModelAndView getCustomerAction(HttpServletRequest request,	HttpServletResponse response) throws Exception {		
		Customer customer=null;
		String customerId = RequestUtil.getParameterNullSafe(request, "customerId");
		if(StringUtils.isNotBlank(customerId)){
			 customer=this.customerManager.getById(new Integer(customerId));			
			 JSONObject jsonMap = customer.getCustomerJsonObject();
			 response.getWriter().println(jsonMap.toString());
		}
		return null;
		
	} 
    
	/**
	 * 群发手机消息
	 * @param request
	 * @param response
	 * @return
	 */
	public ModelAndView sendSms(HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> data = new HashMap<String, Object>();		
		String[] receivers = RequestUtil.getParameterNullSafe(request, "smsReceivers").split(";");
		Map map = new HashMap();
		map.put("content", request.getParameter("smsContent"));
		try{			
			msgSendManager.sendMsg(MsgTemplateConstants.MESSAGE_EMAIL_TO_CUSTOMERS, map, null, null, receivers);
		}catch(Exception e){
			data.put("error", getMessage("customer.sms.fail"));
		}
		data.put("msg", getMessage("customer.sms.success"));
		return getModelAndAjaxJsonView(data);
	}
	
	/**
	 * 群发站内消息
	 * @param request
	 * @param response
	 * @return
	 */
	public ModelAndView sendSystemMsg(HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> data = new HashMap<String, Object>();
		String[] receivers = RequestUtil.getParameterNullSafe(request, "systemMsgReceivers").split(";");
		try{
			//发送消息
			
			Map map = new HashMap();
			//map.put("title", request.getParameter("systemMsgTitle"));
			map.put("content", request.getParameter("systemMsgContent"));
			msgSendManager.sendMsg(MsgTemplateConstants.MESSAGE_EMAIL_TO_CUSTOMERS, map, null, receivers, null);
			map.clear();
			
		}catch(Exception e){
			data.put("error", getMessage("customer.systemMsg.fail"));
		}
		data.put("msg", getMessage("customer.systemMsg.success"));
		return getModelAndAjaxJsonView(data);
	}
    
}
